from src import mysql_Inquire, zzx
from fastapi import FastAPI
from typing import Union
import src.wlff_mysql

app = FastAPI()

################LWZ
@app.get("/book_list",summary="查询书籍列表接口")
def book_list():
    return mysql_Inquire.Inquire_book()

@app.get("/addbook/",summary="添加书籍接口")
def read_item(book_num: Union[int, None] = None, book_name: Union[str, None] = None):
    return mysql_Inquire.add_book(book_num, book_name)

@app.delete("/deleteBook/{book_id}",summary="删除书籍接口")
def delete_itme(book_id: int):
    return mysql_Inquire.delete_book(book_id)

##################WLF
# @app.get("/",summary='select调试接口')
# def read_root():
#     return {"result": wlf.wlff_mysql.selectUser()}
@app.get("/user/login",summary='用户登录接口')
def userCreate(password: Union[str, None] = None, name: Union[str, None] = None):
    return {"result": src.wlff_mysql.login(name, password)}

@app.get("/user/create",summary='用户创建接口')
def userCreate(password: Union[str, None] = None, name: Union[str, None] = None):
    return {"result": src.wlff_mysql.createUser(name, password)}
@app.get("/book/borrow",summary='借书接口')
def borrow(bookId: Union[int, None] = None, num: Union[int, None] = None,password: Union[str, None] = None, name: Union[str, None] = None):
    return {"result": src.wlff_mysql.borrow(bookId, num, name, password)}
@app.get("/book/returnbooks",summary='还书接口')
def returnbooks(bookId: Union[int, None] = None, num: Union[int, None] = None,password: Union[str, None] = None, name: Union[str, None] = None):
    return {"result": src.wlff_mysql.returnBooks(bookId, num, name, password)}

################ZZX
@app.get("/select",summary='查询借阅状态')
def select(bookId: Union[int, None] = None):
    return zzx.select(bookId)
@app.get("/select_list",summary='查询借阅书籍的详细信息')
def select_list(bkId: Union[int, None] = None):
    return zzx.select_list(bkId)